package com.xuxin.baby.model;

import com.xuxin.baby.base.BaseConstant;
import com.xuxin.baby.bean.BaseBean;
import com.xuxin.baby.bean.ReportBean;
import com.xuxin.baby.contract.UserReportContract;
import com.xuxin.baby.network.Retrofit;
import com.xuxin.baby.network.RetrofitApi;
import com.xuxin.baby.network.myObserver;
import com.xuxin.baby.presenter.UserReportPresenter;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.observers.DisposableObserver;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
 * Created by xu_xin
 * Created on 2020/10/23 0023
 * 我的报告
 */
public class UserReportModel implements UserReportContract.Model {
    @Override
    public void getUserReport(UserReportPresenter presenter, String tenantId, String token, String memberId, int skipCount) {
        Retrofit.getInstance().createReq(RetrofitApi.class)
                .getReport(tenantId, token,"1", memberId, skipCount * BaseConstant.page_limit, BaseConstant.page_limit)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new myObserver<ReportBean>() {
                    @Override
                    public void onNextX(@NonNull ReportBean reportBean) {
                        if (reportBean.isSuccess()) {
                            presenter.onSuccess(reportBean);
                        } else {
                            presenter.onError(reportBean);
                        }
                    }
                    @Override
                    public void onError(BaseBean baseBean) {
                        presenter.onError(baseBean);
                    }
                    @Override
                    public void onError(@NonNull Throwable e) {
                        presenter.onError(null);
                    }

                    @Override
                    public void onComplete() {
                        presenter.onComplete();
                    }
                });
    }
}